import { createContext, useContext } from 'react'
import { RadioValue } from './type'

type RadioGroupContextType = {
  /** 指定选中的选项 */
  value: RadioValue[]
  /** 整组失效 */
  disabled: boolean
  /** 选中时触发 */
  check: (val: RadioValue) => void
  /** 未选中时触发 */
  uncheck: (val: RadioValue) => void
}

const RadioGroupContext = createContext<RadioGroupContextType | null>(null)

export const RadioGroupProvider = RadioGroupContext.Provider

export const useRadioGroup = ():RadioGroupContextType | null => useContext(RadioGroupContext)
